<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Excerpt extends CI_model {

	

	public function __construct() {

		parent::__construct();

	}

	function all_demand_excerpt_sql($id) {
		

		
		$this->db->where("flag" ,"Main");
		$this->db->where("demand_id" ,$id);

		$q=$this->db->get('h_excerpt_sql');
		$excerpt_sql_array=array();
		$flag=0;
		foreach($q->result() as $row){
			$excerpt_sql_array[$row->id]=$row->verify_code;			
			$flag=$row->id;
		}
		
		$excerpt_sql_array[$flag];

		//$this->db->where("flag" ,"Main");
		$this->db->where("excerpt_sql !=" ,$excerpt_sql_array[$flag]);
		$this->db->where("verify_code" ,$excerpt_sql_array[$flag]);

		$w=$this->db->get('h_excerpt_sql');
		$sql_ar=array();

		foreach($w->result() as $row){

			$sql_ar[$row->id] =$row->excerpt_sql;
			$sql_ar['verify_code'] =$row->verify_code;	
		}
		
		return $w;


	}
	
	
	function all_object_excerpt_sql($id) {
		

		$_sql=" SELECT * FROM (`h_excerpt_sql`) WHERE `flag` = 'Main' AND `object_id` = '".$id."' ";
		//$this->db->where("flag" , "Main");
		//$this->db->where("object_id" , $id);
		$q=$this->db->query($_sql);
		
		$excerpt_sql_array=array();
		$flag=0;
		foreach($q->result() as $row){
			$excerpt_sql_array[$row->id]=$row->verify_code;			
			$flag=$row->id;
		}
		
		$excerpt_sql_array[$flag];

		//$this->db->where("flag" ,"Main");
		$sql=	" SELECT * FROM (`h_excerpt_sql`) WHERE ".
				" `excerpt_sql` != '".$excerpt_sql_array[$flag] ."' AND " .
				" `verify_code` = '".$excerpt_sql_array[$flag] ."' ";
				
		//$this->db->where("excerpt_sql !=" ,$excerpt_sql_array[$flag]);
		//$this->db->where("verify_code" ,$excerpt_sql_array[$flag]);
		$w=$this->db->query( $sql );
		//$sql_ar=array();
		
		/*
		foreach($w->result() as $row){

			$sql_ar[$row->id] =$row->excerpt_sql;
			$sql_ar['verify_code'] =$row->verify_code;	
		}
		*/
		return $w;


	}

	function update($id , $update_data) {

		$this->db->where('id', $id);
		$this->db->update('h_excerpt_sql', $update_data); 

	}



}
?>